package dhm.com.hpx.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import dhm.com.hpx.R;
import dhm.com.hpx.entity.MyOrderBean;

/**
 * Created by admin
 * 2019/4/29
 * 所有订单适配器
 */
public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder> {

    private Context context;


    List<MyOrderBean.DataBean> list=new ArrayList<>();

    //1待支付，2已完成
    private String orderStatus="1";

    public OrderAdapter(Context context,String orderStatus) {
        this.context = context;
        this.orderStatus=orderStatus;
    }

    public void setList(List<MyOrderBean.DataBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        ViewHolder viewHolder;
        View view= LayoutInflater.from(context).inflate(R.layout.item_order, null);
        viewHolder=new ViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder viewHolder, final int i) {
        //3铂金会员，2黄金会员，1白金会员
        switch (list.get(i).getPayType()){
            case 1:
                viewHolder.title.setText("月卡会员");
                viewHolder.q.setText("可享受8项权益");
                break;
            case 2:
                viewHolder.title.setText("季卡会员");
                viewHolder.q.setText("可享受8项权益");
                break;
            case 3:
                viewHolder.title.setText("年卡会员");
                viewHolder.q.setText("可享受10项权益");
                break;
                default:
        }

        viewHolder.price.setText(list.get(i).getRealTotalMoney());
        if (orderStatus.equals("1")){
            //待支付
            viewHolder.topay.setVisibility(View.VISIBLE);
            viewHolder.complate.setVisibility(View.GONE);
            viewHolder.del.setVisibility(View.VISIBLE);
            viewHolder.del.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    onIntentClick.item(i);
                }
            });
        }else {
            viewHolder.topay.setVisibility(View.GONE);
            viewHolder.complate.setVisibility(View.VISIBLE);
            viewHolder.del.setVisibility(View.GONE);
        }

        viewHolder.topay.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClick.item(i,view);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        public TextView title;
        public TextView q;
        public TextView price;
        public TextView del;
        public Button topay;
        public ImageView complate;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            title=itemView.findViewById(R.id.title);
            q=itemView.findViewById(R.id.q);
            topay=itemView.findViewById(R.id.topay);
            price=itemView.findViewById(R.id.price);
            del=itemView.findViewById(R.id.del);
            complate=itemView.findViewById(R.id.complate);
        }
    }

    private OnClick onClick;
    public void setdeleteClick(OnClick onClick) {
        this.onClick = onClick;
    }
    public interface OnClick{
        void item(int posttion,View view);
    }

    private OnIntentClick onIntentClick;
    public void setaddClick(OnIntentClick onClick) {
        this.onIntentClick = onClick;
    }
    public interface OnIntentClick{
        void item(int position);
    }



}

